package com.cskaoyan.day2.collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Common-zhou
 * @since 2023-02-28 10:25
 */
public class CollectionDemo3 {
    public static void main(String[] args) {
        //    ---------------------------------特殊方法---------------------------------
        //    void clear()： 清空collection
        //    boolean equals(Object o) ： 判断是否相等
        //    int hashCode()： 计算hashCode
        //    boolean isEmpty(): 是否为空
        //    int size()： collection里面的元素个数

        //testClear();
        //
        //testEquals();

        //testHashCode();
        //
        //testHashCode1();

        testIsEmpty();

    }

    private static void testIsEmpty() {
        //    boolean isEmpty(): 是否为空

        Collection<String> collection = new ArrayList<>();

        // 返回boolean  代表集合是否为空
        System.out.println(collection.isEmpty());

        collection.add("zs");
        collection.add("ls");
        System.out.println(collection.isEmpty());

        collection.clear();
        System.out.println(collection.isEmpty());





    }

    private static void testHashCode1() {
        Collection<String> collection = new ArrayList<>();
        collection.add("zs");
        collection.add("ls");

        Collection<String> collection1 = new ArrayList<>();
        collection1.add("zs");
        collection1.add("ls");

        System.out.println(collection.hashCode());
        System.out.println(collection1.hashCode());

    }

    private static void testHashCode() {
        Collection<String> collection = new ArrayList<>();
        System.out.println(collection.hashCode());

        // Collection重写了hashCode  与里面的元素有关
        collection.add("zs");
        System.out.println(collection.hashCode());

        collection.add("zs");
        System.out.println(collection.hashCode());

    }

    private static void testEquals() {
        Collection<String> collection = new ArrayList<>();
        collection.add("zs");
        collection.add("ls");

        Collection<String> collection1 = new ArrayList<>();
        collection1.add("zs");
        collection1.add("ls");
        //collection1.add("ls");

        System.out.println(collection.equals(collection1));

    }

    private static void testClear() {
        Collection<String> collection = new ArrayList<>();

        collection.add("zs");
        collection.add("ls");
        collection.add("wu");
        System.out.println(collection);

        collection.clear();
        System.out.println(collection);

    }
}
